/**
 * 
 */
package com.hirstlogics.boxarrow.box;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;

import com.hirstlogics.boxarrow.model.IdManager;
import com.hirstlogics.boxarrow.xml.Persist;

/**
 * @author steve
 *
 */
public class AtomicBox extends Box {
	
	protected String name = "";
	
	public AtomicBox() {
		
	}
	public AtomicBox(String name) {
		this.name  = name;
		this.id = IdManager.getInstance().createId();
	}


	/* (non-Javadoc)
	 * @see com.hirstlogics.boxarrow.box.Box#getName()
	 */
	@Override
	public String getName() {
		return name;
	}
	

	/* (non-Javadoc)
	 * @see com.hirstlogics.boxarrow.box.Box#render(javax.xml.stream.XMLStreamWriter)
	 */
	@Override
	public void render(XMLStreamWriter writer) throws XMLStreamException {
		String myClass = this.getClass().getCanonicalName();
		writer.writeStartElement(Persist.PREFIX,"Box", Persist.BOXARROW);
		writer.writeAttribute("id", String.valueOf(getId()));
		writer.writeAttribute("sort", myClass);
		writer.writeCharacters(getName());
		writer.writeEndElement();
	}

	@Override
	public void readContents(XMLStreamReader read) {
		try {
			name = read.getElementText();
		} catch (XMLStreamException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
